package tests.view_generation;

import es.upm.gib.mappingAPI2.RDF2NL.NLText;
import es.upm.gib.mappingAPI2.RDF2NL.RDF2NL;
import es.upm.gib.mappingAPI2.Restriction;
import es.upm.gib.mappingAPI2.View;
import es.upm.gib.mappingAPI2.generate.PhysicalViewGenerator;
import es.upm.gib.owlbasicmodel2.OWLBasicModel2;

import java.io.File;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: Alberto
 * Date: 7/08/13
 * Time: 13:52
 * To change this template use File | Settings | File Templates.
 */
public class TestSample01 {

    public static void main(String args[]) {
        try {
            OWLBasicModel2 model = OWLBasicModel2.parseFile("."+ File.separator+"etc"+File.separator+"view_generation_samples"+ File.separator+"sample01"+ File.separator+"sample01.owl");

            PhysicalViewGenerator physicalViewGenerator = new PhysicalViewGenerator(model, true);

            System.out.println("begin...");
            View view2;

            // text discard class
            /*physicalViewGenerator.specifyView();
            View view2 = physicalViewGenerator.currentView();
            printNL(view2, model);
            System.out.println("---");*/

            physicalViewGenerator.specifyView(1);
            view2 = physicalViewGenerator.currentView();
            printNL(view2, model);
            System.out.println("---");

            physicalViewGenerator.discardClass(1, 0);
            view2 = physicalViewGenerator.currentView();
            printNL(view2, model);
            System.out.println("---");


            physicalViewGenerator.acceptView();
            view2 = physicalViewGenerator.currentView();
            printNL(view2, model);
            physicalViewGenerator.discardProperty(2);
            view2 = physicalViewGenerator.currentView();
            printNL(view2, model);
            physicalViewGenerator.discardProperty(2);
            view2 = physicalViewGenerator.currentView();
            printNL(view2, model);
            physicalViewGenerator.discardProperty(2);
            view2 = physicalViewGenerator.currentView();
            printNL(view2, model);
            physicalViewGenerator.discardProperty(2);
            view2 = physicalViewGenerator.currentView();
            printNL(view2, model);








            System.out.println(physicalViewGenerator.currentProgress());
            //physicalViewGenerator.specifyView();
            physicalViewGenerator.specifyView("http://www.sample01.owl#reveals");
            System.out.println(physicalViewGenerator.currentProgress());
            physicalViewGenerator.specifyView(1);
            physicalViewGenerator.setRestriction(1, 1, new Restriction(Restriction.Operator.EQUAL, "5", Restriction.Range.INTEGER));
            physicalViewGenerator.setIdentifier(1, 1);
            System.out.println(physicalViewGenerator.currentProgress());
            View view = physicalViewGenerator.currentView();
            System.out.println(view);
            printNL(view, model);
            physicalViewGenerator.generalizeView(1);
            System.out.println(physicalViewGenerator.currentProgress());
            view = physicalViewGenerator.currentView();
            while (view != null) {
                System.out.println(view);
                printNL(view, model);
                physicalViewGenerator.acceptView();
                view = physicalViewGenerator.currentView();
                System.out.println(physicalViewGenerator.currentProgress());
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private static void printNL(View view, OWLBasicModel2 model) {
        List<NLText> nlTextList = RDF2NL.viewToNL(view, model);
        for (NLText nlText : nlTextList) {
            System.out.println(nlText.toPlainText());
        }
    }

}
